package com.sbdev.controller.db;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/role")
public class DataSourceController {

    // 注入JdbcTemplate，它由Spring Boot自动创建不需要我们干预
    @Autowired
    private JdbcTemplate jdbcTemplate = null;

    /**
     * 获取角色
     * @param id 角色编号
     * @return 角色信息
     */
    @GetMapping("/info/{id}")
    public Map<String, Object> getRole(@PathVariable("id") Long id) {
        System.out.println("DataSource类型：" + jdbcTemplate.getDataSource().getClass().getName());
        Map<String, Object> roleMap = null;
        String sql = "select id, role_name, note from t_role where id = ?";
        roleMap = jdbcTemplate.queryForMap(sql, id);
        return roleMap;
    }
}
